<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="org.json.simple.*" %>
<%@ page import="java.util.*" %>
<%@ page import="mfuny.ggongal.admin.http.HttpGame" %>
<%@ page import="mfuny.ggongal.admin.debug.Debug" %>
<%@ page import="mfuny.ggongal.admin.http.HttpGameDecoder" %>
<%@ page trimDirectiveWhitespaces="true" %>
<%
request.setCharacterEncoding( "utf-8" );
response.setContentType( "text/html; charset=utf-8" );

HttpGame game = new HttpGame();
HttpGameDecoder decoder = new HttpGameDecoder();

String ggongal = request.getParameter("ggongal");
if ( ggongal != null ) {
	try {
		String result = decoder.receiveDecode(ggongal);
		out.print(result);
	} catch ( Exception e ) {
		Debug.toDebugFile(e, "ggongal");
	}
	return;
}

String tag = request.getParameter("tag");

//게임 시작시..
if(tag.equals("game_start")) {
	try{
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("id", request.getParameter("id"));
		params.put("ad_no", request.getParameter("ad_no"));
		JSONObject json = game.game_start(params);
		out.print(json.toJSONString());
	}catch(Exception e){
		Debug.toDebugFile(e, tag);
	}
}

//게임 끝..
else if(tag.equals("game_end")) {
	try{
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("no", request.getParameter("play_no"));
		params.put("score", Integer.parseInt(request.getParameter("score")));
		params.put("playtime", Float.parseFloat(request.getParameter("playtime")));
		params.put("etc", request.getParameter("etc"));
		JSONObject json = game.game_end(params);
		out.print(json.toJSONString());
	}catch(Exception e) {
		Debug.toDebugFile(e, tag);
	}
}

//경품 받을지 여부 결정.
else if(tag.equals("game_setReceive")) {
	try{
		int mygift_no = Integer.parseInt(request.getParameter("mygift_no"));
		int receive = Integer.parseInt(request.getParameter("receive"));
		int result = game.game_setReceive(mygift_no, receive);
		out.print(result);
	}catch(Exception e) {
		Debug.toDebugFile(e, tag);
	}
}

//게임 끝난 후 랭킹만..
else if(tag.equals("game_getRank")) {
	try {
		HashMap<String, Object> params = new HashMap<String, Object>();
		params.put("id", request.getParameter("id"));
		params.put("ad_no", request.getParameter("ad_no"));
		JSONObject json = game.game_getRank(params);
		out.print(json.toJSONString());
	} catch ( Exception e ) {
		Debug.toDebugFile(e, tag);
	}
}

%>